import request from '@/utils/ruizhiRequest'
// 创建一个数据指标
export const CreateNewIndex = (data) => {
  return request({
    url: '/v1/admin/dataindex/create/',
    method: 'post',
    data,
  })
}

// 查询数据指标
export const RetrieveIndex = (kw = null, page = 1, pageSize = 50) => {
  return request({
    url: '/v1/admin/dataindex/retrieve/',
    method: 'get',
    params: { kw, page, page_size: pageSize },
  })
}

// 修改数据指标
export const UpdateIndex = (data) => {
  return request({
    url: '/v1/admin/dataindex/update/',
    method: 'put',
    data,
  })
}

// 检查平台下指标ID是否存在
export const CheckIndexExist = (plat, plat_id) => {
  return request({
    url: '/v1/admin/dataindex/exist/',
    method: 'get',
    params: { plat, plat_id },
  })
}

// 创建指标分组
export const CreateIndexGroup = (data) => {
  return request({
    url: '/v1/admin/dataindex/group/create/',
    method: 'post',
    data,
  })
}

// 查询指标分组
export const RetrieveIndexGroup = (vcode, parent) => {
  return request({
    url: '/v1/admin/dataindex/group/retrieve/',
    method: 'get',
    params: { vcode, parent },
  })
}
// 删除指标分组
export const DeleteIndexGroup = (gid) => {
  return request({
    url: '/v1/admin/dataindex/group/delete/',
    method: 'delete',
    data: { gid },
  })
}

// 更新指标分组名称等
export const UpdateIndexGroup = (data) => {
  return request({
    url: '/v1/admin/dataindex/group/update/',
    method: 'put',
    data,
  })
}

// 查询分组内的指标
export const GroupIndex = (gid) => {
  return request({
    url: '/v1/admin/dataindex/groupIndex/retrieve/',
    method: 'get',
    params: { gid },
  })
}

// 更新分组内的指标
export const UpdateGroupIndex = (data) => {
  return request({
    url: '/v1/admin/dataindex/groupIndex/update/',
    method: 'put',
    data,
  })
}

// 添加组内指标
export const CreateGroupIndex = (data) => {
  return request({
    url: '/v1/admin/dataindex/groupIndex/create/',
    method: 'post',
    data,
  })
}

// 清空组内指标
export const ClearGroupIndex = (gid) => {
  return request({
    url: '/v1/admin/dataindex/groupIndex/clear/',
    method: 'delete',
    data: { gid },
  })
}

// 删除组内一个指标
export const DeleteGroupIndexOne = (giid) => {
  return request({
    url: '/v1/admin/dataindex/groupIndex/delete/',
    method: 'delete',
    data: { giid },
  })
}

// 查询指标具体数据
export const IndexDetailData = (indexId, page = 1, page_size = 100) => {
  return request({
    url: `/v1/admin/dataindex/${indexId}/`,
    method: 'get',
    params: { page, page_size },
  })
}

// 增加指标具体数据
export const CreateIndexDetail = (indexId, data) => {
  return request({
    url: `/v1/admin/dataindex/${indexId}/`,
    method: 'post',
    data,
  })
}

// 修改具体指标行
export const UpdateIndexDetail = (indexId, data) => {
  return request({
    url: `/v1/admin/dataindex/${indexId}/`,
    method: 'put',
    data,
  })
}
// 清空指标数据
export const DeleteIndexTable = (indexId) => {
  return request({
    url: `/v1/admin/dataindex/${indexId}/`,
    method: 'delete',
  })
}
